<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>器材管理</title>
<%-- <script type="text/javascript"
	src="${pageContext.request.contextPath }/scripts/jquery-1.7.2.js"></script>
<script src="bootstrap/js/bootstrap.js"></script> --%>
<link href="${pageContext.request.contextPath }/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
<script  src="bootstrap/js/jquery-3.2.0.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>

<script type="text/javascript">
$(function() {
	var epList = '${session.ep_list}';
	if(epList.length==0){
		$("#ep_list").hide();
	}else{
		$("#ep_list").show;
	}
	
	var epId;
	$(".epName").click(function() {
		var id = $(this).parent().parent().children().eq(0).text();
		epId = id;
		var name = $(this).parent().parent().children().eq(1).text();
		name = $.trim(name);
		var equipmentNum = $(this).parent().parent().children().eq(2).text();
		var equipmentRestNum = $(this).parent().parent().children().eq(3).text();
		var equipmentPrice = $(this).parent().parent().children().eq(4).text();
		var equipmentCost = $(this).parent().parent().children().eq(5).text();
		var equipmentRentTime = $(this).parent().parent().children().eq(6).text();
		
		$("#id").val(id);
		$("#name").val(name);
		$("#equipmentNum").val(equipmentNum);
		$("#equipmentRestNum").val(equipmentRestNum);
		$("#equipmentPrice").val(equipmentPrice);
		$("#equipmentCost").val(equipmentCost);
		$("#equipmentRentTime").val(equipmentRentTime);
		
	});

	$(".ep_from_btn").click(function() {
		var btn_val = $(this).val(); 
		
		if(btn_val=="清空"){
			$("#ep_message  :input")  
			 .not(":button")  
			 .val("") ;
			return false;
		}
		
		if(btn_val=="查询"){
			$("#ep_message").attr("action","em-queryEp");
			$("#ep_message").submit();
			return false;
		}
			
		//获取输入框中的器材名字
		var epNames = "";
		var inputEpName = $.trim($("#name").val());
		
		//获取现在所有的器材名
		$(".epName").each(function(){
			epNames+=$(this).text() + ","; 
		});
		
		//判断名字是否存在
		var epName = epNames.split(",");
		var sign = 0;
		for(var i = 0 ; i <epName.length-1 ; i++){
			if(inputEpName==epName[i]){
				sign = 1;
				break;
			}
		}
		
		//添加的器材存在
		if(sign==1){
			if(btn_val=="修改"){
				//编号是无法修改的
				$("#id").val(epId);
				
 				$("#ep_message").attr("action","em-modifiEp");
				$("#ep_message").submit(); 
				return false;
			}
			if(btn_val=="添加"){
				alert(inputEpName + "已经存在");
				return false;
			}
		}else{
			if(btn_val=="修改"){
				alert("器材" + inputEpName + "不存在");
				return false;
			}
			if(btn_val=="添加"){
				alert("添加");
				$("#ep_message").attr("action","em-addEp");
				$("#ep_message").submit();
				return false;
			}
		}
		
	});
	
});


</script>
<style>
form{
	margin:0 auto;
	  left: 50%;
  display: inline-block;
  position: relative;
  transform: translateX(-50%);
}
form input{
	margin-left:20px;
	margin-top:10px;
}
table{
	margin:0 auto;
}
table tr th,table tr td{
	padding-left:15px;
}
</style>

</head>
<body>
	<%@include file = "../navigationBar.jsp" %> 
<div class='container'>
	<form action="em-queryEp" method="post" id = "ep_message">	
		器材编号<input id="id" type="text" name="equipmentId"  onkeyup="value=this.value.replace(/\D+/g,'')"
									value="${requestScope.query_ep.equipmentId}" />
		<br/>
		器材名称<input id="name" type="text" name="equipmentName" value="${requestScope.query_ep.equipmentName}"/>
		<br/>
		器材总数<input id="equipmentNum" type="text" name="equipmentNum" onkeyup="value=this.value.replace(/\D+/g,'')" 
									value="${requestScope.query_ep.equipmentNum}"/>
		<br/>
		器材剩余数<input id="equipmentRestNum" type="text" name="equipmentRestNum" onkeyup="value=this.value.replace(/\D+/g,'')" 
									value="${requestScope.query_ep.equipmentRestNum}"/>
		<br/>
		器材单件购买价格<input id="equipmentPrice" type="text" name="equipmentPrice" value="${requestScope.query_ep.equipmentPrice}"/>
		<br/>
		器材租借费用(天/元)<input id="equipmentCost" type="text" name="equipmentCost" value="${requestScope.query_ep.equipmentCost}"/>
		<br/>
		可租借的最长天数<input id="equipmentRentTime" type="text" name="equipmentRentTime" onkeyup="value=this.value.replace(/\D+/g,'')" 
									value="${requestScope.query_ep.equipmentRentTime}"/>
		<br/>
		<input class="ep_from_btn" type="button" value="查询"/>
		<input class="ep_from_btn" type="button" value="修改"/>
		<input class="ep_from_btn" type="button" value="添加"/>
		<input class="ep_from_btn" type="button" value="清空"/>
	</form>
	
	
	<hr>
	
	
	<div id="ep_list">
		<table>
			<tr class="title">
				<th>器材编号</th>
				<th>器材名称</th>
				<th>器材总数</th>
				<th>器材剩余数</th>
				<th>器材单件购买价格</th>
				<th>器材租借费用(天/元)</th>
				<th>可租借的最长天数</th>
				<th>添加时间</th>
				<th>操作</th>
			</tr>

			<!-- 遍历开始 -->
			<s:iterator value="#session.ep_list" var="ep" status="st">
				<tr>
					<td><s:property value="#ep.equipmentId" /></td>
					<td>
						<a class="epName" href="#" ><s:property	value="#ep.equipmentName" /></a>
					</td>
					<td><s:property value="#ep.equipmentNum" /></td>
					<td><s:property value="#ep.equipmentRestNum" /></td>
					<td><s:property value="#ep.equipmentPrice" /></td>
					<td><s:property value="#ep.equipmentCost" /></td>
					<td><s:property value="#ep.equipmentRentTime" /></td>
					<td><s:property value="#ep.equipmentBugTime" /></td>
					
					<td><a href="em-epDelete?deleteEpId=<s:property value="#ep.equipmentId"/>"
						onclick="javascript: return confirm('真的要删除吗？');">删除</a></td>
				</tr>
			</s:iterator>
			<!-- 遍历结束 -->
		</table>

	</div>
	</div>
	
	
</body>
</html>